package com.ocr.utils;

import java.util.ArrayList;

public class Line {

	public int top;
	public int bottom;
	ArrayList<Word> words;

	int current_word_index = 0;
	Word current_word;

	public Line(int top, int bottom) {

		this.top = top;
		this.bottom = bottom;

	}

	/**
	 * 
	 */
	public boolean has_next_word() {

		if (words == null)
			return false;
		if (current_word_index < words.size())
			return true;
		return false;

	}

	/**
	 * 
	 * @return
	 */
	public Word next_word() {

		if (words != null) {
			Word word = words.get(current_word_index);
			current_word_index++;
			return word;
		}
		return null;

	}

	/*
	 * has next symbol
	 */
	public boolean has_next_symbol() {

		if (has_next_word())
			return true;
		else if (current_word.has_next_symbol())
			return true;
		else
			return false;

	}

	/**
	 * 
	 * @return next symbol
	 */
	public Symbol next_symbol() {

		if (current_word.has_next_symbol())
			current_word.next_symbol();
		else if (has_next_word()) {
			current_word = next_word();
			return current_word.next_symbol();
		}
		return null;

	}

	/**
	 * 
	 * @param c
	 */
	public void setSymbolResult(char c) {

		words.get(current_word_index).setSymbolResult(c);

	}

	/**
	 * 
	 * @return
	 */
	public String getRecognitionLine() {

		String result = "";

		for (Word w : words) {
			result += w.getRecognitionWord();
		}
		return result;

	}

	public ArrayList<Word> getWords() {
		return words;
	}

	public void setWords(ArrayList<Word> words) {
		this.words = words;
		current_word = words.get(0);
	}

	public String toString() {
		String newline = System.getProperty("line.separator");
		String info = "Top " + top + ";" + "Bottom:" + bottom + "; Words:"
				+ words.size() + newline;

		for (Word w : words) {
			info += w.toString() + newline;
		}

		return info;
	}
}
